<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="../include/tag.jsp" %>
<html>
<head>
    <title>发布核销码</title>
    <link rel="stylesheet" href="${ctxStatic}/layui-v2.2.45/layui/css/layui.css">
    <link rel="stylesheet" href="${ctx}/css/ui/circle/set_tag.css">
    <link rel="stylesheet" href="${ctx}/css/common/common.css">
    <script type="text/javascript" src='${ctxStatic}/jquery/jquery-2.1.4.min.js'></script>
    <script type="text/javascript" src="${ctx}/script/common/util.js"></script>
</head>
<body>

<div class="tag-wrap">
    <form id="myForm" class="layui-form pl10" method="post" action="${ctx}/coupon/couponCode/save.do">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label" style="width: 50px;padding-left: 0px;">核销码<span class="f-verify-red">*</span></label>
                <div class="layui-input-inline" style="margin-left: 70px;">
                    <input type="text" name="verifyCode" lay-verify="verifyCode" autocomplete="off" class="layui-input" value="${couponCode.verifyCode}">
                    <input type="hidden" name="id" value="${couponCode.id}"/>
                    <input type="hidden" name="couponId" value="${coupon.id}"/>
                </div>
            </div>
        </div>
    </form>
</div>
</body>
<%@include file="../include/incScript.jsp" %>
<script type="text/javascript">
    var layer, form;
    $(function () {
        layui.use(['layer', 'form'], function () {
            layer = layui.layer, form = layui.form;
        });
    })

    function doSubmit() {
        var verifyCode = $("[name=verifyCode]").val();
        if (verifyCode == "") {
            util.layerMsgError("核销码不能为空")
            return false;
        }

        var flag = false;
        $.ajax({
            url: '${ctx}/coupon/couponCode/checkVerifyCode.do',
            type: "POST",
            dataType: "JSON",
            async: false,
            data: $("#myForm").serializeArray(),
            success: function (result) {
                flag = result;
            }
        });

        if (flag == true) {
            $.ajax({
                url: '${ctx}/coupon/couponCode/save.do',
                type: "POST",
                dataType: "JSON",
                async: false,
                data: $("#myForm").serializeArray(),
                success: function (res) {
                    if (res.success) {
                        util.layerMsgSuccess("保存成功", function () {
                            parent.submitFunction('#myForm');
                        })
                    }
                    flag = res.success;
                }
            });
        } else {
            util.layerMsgError("核销码已存在")
            return false;
        }
        return flag;
    }
</script>
</html>